import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDMonster {
	/**ID*/
	id,
	/**怪物id，用于获取模型*/
	unitID,
	/**等级*/
	level,
	/**数值表*/
	math,
	/**主动技能等级*/
	activeSkillLv,
	/**被动技能等级*/
	passiveSkillLv,
	/**模型大小*/
	scale,
	/**宠物1--[宠物id，星级，技能等级]*/
	pet_1,
	/**宠物2*/
	pet_2,
	/**宠物3*/
	pet_3,
	/**宠物4*/
	pet_4,

	/**枚举数量*/
	EnumCount
}



export class CDMonster{
	/**ID*/
	public id: number;
	/**怪物id，用于获取模型*/
	public unitID: number;
	/**等级*/
	public level: number;
	/**数值表*/
	public math: number;
	/**主动技能等级*/
	public activeSkillLv: number;
	/**被动技能等级*/
	public passiveSkillLv: number;
	/**模型大小*/
	public scale: number;
	/**宠物1--[宠物id，星级，技能等级]*/
	public pet_1: number[];
	/**宠物2*/
	public pet_2: number[];
	/**宠物3*/
	public pet_3: number[];
	/**宠物4*/
	public pet_4: number[];


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDMonster.id: return this.id;
			case E_CDMonster.unitID: return this.unitID;
			case E_CDMonster.level: return this.level;
			case E_CDMonster.math: return this.math;
			case E_CDMonster.activeSkillLv: return this.activeSkillLv;
			case E_CDMonster.passiveSkillLv: return this.passiveSkillLv;
			case E_CDMonster.scale: return this.scale;
			case E_CDMonster.pet_1: return this.pet_1;
			case E_CDMonster.pet_2: return this.pet_2;
			case E_CDMonster.pet_3: return this.pet_3;
			case E_CDMonster.pet_4: return this.pet_4;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDMonster.id: this.id = v; break;
			case E_CDMonster.unitID: this.unitID = v; break;
			case E_CDMonster.level: this.level = v; break;
			case E_CDMonster.math: this.math = v; break;
			case E_CDMonster.activeSkillLv: this.activeSkillLv = v; break;
			case E_CDMonster.passiveSkillLv: this.passiveSkillLv = v; break;
			case E_CDMonster.scale: this.scale = v; break;
			case E_CDMonster.pet_1: this.pet_1 = v; break;
			case E_CDMonster.pet_2: this.pet_2 = v; break;
			case E_CDMonster.pet_3: this.pet_3 = v; break;
			case E_CDMonster.pet_4: this.pet_4 = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDMonster> = new HashMap<number, CDMonster>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDMonster[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDMonster();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].unitID = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].level = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].math = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].activeSkillLv = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].passiveSkillLv = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].scale = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].pet_1 = [];
			const attrArray = list[i].pet_1;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].pet_2 = [];
			const attrArray = list[i].pet_2;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].pet_3 = [];
			const attrArray = list[i].pet_3;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].pet_4 = [];
			const attrArray = list[i].pet_4;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDMonster{
		return this.datas ? this.datas.get(id) : null;
	}
}
